package ru.evga.inse.server.gwt.user.client.menu;


public abstract class MenuProcessor<T>
{
    private final T m_defaultValue;

    private T m_result;

    /**
     * Create an instance with a null default value.
     */
    public MenuProcessor()
    {
        m_defaultValue = null;
    }

    /**
     * Create an instance with the given default value.
     * 
     * @param the
     *            value that will be returned by {@link #process} if
     *            {@link #setResult} is not called.
     */
    public MenuProcessor(T defaultValue)
    {
        this.m_defaultValue = defaultValue;
    }

    public abstract void handleGeneral();

    public abstract void handleRealty();

    public abstract void handleForum();

    public abstract void handleAdmin();

    public T process(MenuItem item)
    {
        setResult(m_defaultValue);
        if (MenuItem.GENERAL == item)
        {
            handleGeneral();
        }
        else if (MenuItem.REALTY == item)
        {
            handleRealty();
        }
        else if (MenuItem.FORUM == item)
        {
            handleRealty();
        }
        else if (MenuItem.ADMIN == item)
        {
            handleAdmin();
        }
        return m_result;
    }

    /**
     * Set the value to return from a call to {@link #process(Class)} or
     * {@link #process(Object)}.
     * 
     * @param result
     *            the value to return
     */
    protected void setResult(T result)
    {
        this.m_result = result;
    }
}
